﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WindowsPhoneEssentials.Expressions;

namespace WindowsPhoneEssentials.Tests.Expressions
{
    [TestClass]
    public class PropertyInfoTests
    {
        [TestMethod]
        public void property_info_resolved_for_instance_property()
        {
            // arrange
            var instance = new TestClass();

            // act
            var prop = PropertyResolver.PropertyFor(() => instance.TestProp);

            // assert
            Assert.AreEqual("TestProp", prop.Name);
            Assert.AreEqual(typeof(string), prop.PropertyType);
        }

        [TestMethod]
        public void property_info_resolved_for_type_property()
        {
            // arrange/act
            var prop = PropertyResolver.PropertyFor((TestClass c) => c.TestProp);

            // assert
            Assert.AreEqual("TestProp", prop.Name);
            Assert.AreEqual(typeof(string), prop.PropertyType);
        }

        [TestMethod]
        public void name_resolved_for_instance_property()
        {
            // arrange
            var instance = new TestClass();

            // act
            var name = PropertyResolver.NameFor(() => instance.TestProp);

            // assert
            Assert.AreEqual("TestProp", name);
        }

        [TestMethod]
        public void name_resolved_for_type_property()
        {
            // arrange/act
            var name = PropertyResolver.NameFor((TestClass c) => c.TestProp);

            // assert
            Assert.AreEqual("TestProp", name);
        }

        public class TestClass
        {
            public string TestProp { get; set; }
        }
    }
}
